﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharedLib.MessageFramework;

namespace SharedLib.MessageFramework.Messages
{
    public class TaskMessage<TData, TResult> : TaskMessage
    {
        Type _handler;
        public override Type Handler
        {
            get { return _handler; }
        }

        public TaskMessage(object sender, Type handler, MessageCallback callback, IAppMessage parentMessage = null)
            : this(sender, handler, null, null, parentMessage)
        {
        }

        public TaskMessage(object sender, Type handler, MessageData<TData> data, IAppMessage parentMessage = null)
            : this(sender, handler, data, null, parentMessage)
        {
        }

        public TaskMessage(object sender, Type handler, MessageData<TData> data, string customizedID, IAppMessage parentMessage = null)
            : base(sender, handler, data, customizedID, parentMessage)
        {
            _handler = handler;
        }

        public TData GenericData
        {
            get
            {
                if (Data != null && Data is MessageData<TData>)
                    return ((MessageData<TData>)Data).Data;
                return default(TData);
            }
        }

        public TResult GenericResult
        {
            get 
            {
                if(Result != null && Result is TResult)
                    return (TResult)Result;
                return default(TResult);
            }
            set
            {
                Result = value;
            }
        }


    }
}
